package object;

/**
 * object的toString()
 *
 */

public class ObjectDemo {
    public static void main(String[] args) {
        String s1=new String("hello");
        String s2=new String("hello");
        //String类重写了equals()来比较字符串内容是否相同
        System.out.println(s1.equals(s2));//true

        StringBuilder builder1=new StringBuilder("hello");
        StringBuilder builder2=new StringBuilder("hello");
        //StringBuilder类没有重写equals(),因此调用的还是Object类的equals()比较地址
        System.out.println(builder1.equals(builder2));//false

        //s1和builder的类型不同，所以equals()返回的是false
        System.out.println(s1.equals(builder1));//false



        /*
        调用Object类 的equals(),内部还是在用==

        Point p1=new Point(100,200);
        Point p2=new Point(100,200);
        System.out.println(p1==p2);//false,==比较的是地址
        System.out.println(p1.equals(p2));//false
        */


       /*
        Point p1=new Point(200,200);
        System.out.println(p1);
        System.out.println(p1.toString());

        */
    }
}
